#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

char buf1[] = "1234567890";
char buf2[] = "ABCDEFGHIJ";
char buf3[] = "abcdefghij";

int main(int argc, char *argv[])
{
	int fd;
	if((fd = creat("./seek_test",0644)) < 0) {
		perror("create error\n");
		exit(EXIT_FAILURE);
	}
	else{
		printf("create success\n");
	}
	if(write(fd, buf1, 10) != 10) {
		perror("write error\n");
		exit(EXIT_FAILURE);
	}
	else{
		printf("write buf1 success\n");
	}
	if(lseek(fd, 20, SEEK_SET) == -1) {
		perror("lseek error\n");
		exit(EXIT_FAILURE);
	}
	else{
		printf("seek 20 success\n");
	}
	if (write(fd, buf2, 10) != 10) {
		perror("write error\n");
		exit(EXIT_FAILURE);
	}
	else{
		printf("write buf2 success\n");
	}
	if(lseek(fd, 10, SEEK_SET) == -1) {
		perror("lseek error\n");
		exit(EXIT_FAILURE);
	}
	else{
		printf("seek 10 success\n");
	}
	if(write(fd, buf3, 10) != 10) {
		perror("write error\n");
		exit(EXIT_FAILURE);
	}
	else{
		printf("write buf3 success\n");
	}
	
	return 0;
}
